/*
 * @Author: 刘晟勇
 * @Date: 2021-10-14 18:35:59
 * @LastEditTime: 2021-10-22 11:04:17
 * @Description: product-list组件
 */
import axios from "./require.js"

/**
 * @description: 获取商品列表
 * @param {Object} params
 * @param {Function} callback
 * @return {Array}
 */
export async function getProductList(params, callback) {
  const { data } = await axios.get('product/list', {
    params
  })
  const productList = data.list.reduce((targe, item) => {
    targe.push({
      imgUrl: item.imageHost + item.mainImage,
      ...item
    })
    return targe
  }, [])
  callback(productList)
}

/**
 * @description: 获取商品详情
 * @param {Object} params
 * @param {Function} callback
 * @return {Object}
 */
export async function getProductDetail(params, callback) {
  const { data } = await axios.get('product/detail', {
    params
  })
  callback(data)
}

export async function getProductRecommend(callback) {
  const { data } = await axios.get('product/recommend')
  callback(data)
}
